<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main"/>
    <g:set var="entityName" value="${message(code: 'contact.label', default: 'Contact')}"/>
    <title>新增共有人信息</title>
</head>

<body>
<div class="small-header">
    <div class="hpanel">
        <div class="panel-body">
            <div id="hbreadcrumb" class="pull-right">
                <ol class="hbreadcrumb breadcrumb">
                    <li>PLS CINDATA</li>
                    <li>
                        <g:link controller="menu" action="index">CINDATA</g:link>
                    </li>
                    <li class="active">
                        <span>新增共有人信息</span>
                    </li>
                </ol>
            </div>

            <h2 class="font-light m-b-xs">
                新增共有人信息
            </h2>
        </div>
    </div>
</div>

<g:form class="createForm" action="saveCommonContact">
    <g:if test="${flash.message}">
        <div class="message alert alert-info" role="status">${flash.message}</div>
    </g:if>
    <g:hasErrors bean="${this.menu}">
        <ul class="errors" role="alert">
            <g:eachError bean="${this.menu}" var="error">
                <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message
                        error="${error}"/></li>
            </g:eachError>
        </ul>
    </g:hasErrors>

    <div class="content animate-panel">
        <div class="row">
            <div class="hpanel hblue">
                <div class="panel-heading">
                    基本信息
                </div>

                <div class="panel-body form-horizontal">

                    <div class="form-group">
                        <label class="col-md-2 control-label is-required">姓名</label>
                        <div class="col-md-3">
                            <g:textField class="form-control" type="text" name="fullName" id="fullName" value="${this.contact?.fullName}"/>
                        </div>

                        <label class="col-md-2 control-label is-required">共有人类型</label>
                        <div class="col-md-3">
                            <g:select class="form-control" name="typeId" id="typeId" optionKey="id" optionValue="name" from="${com.cindata.dictionary.ContactType.list()}" noSelection="${["": '请选择共有人类型']}"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label is-required">性别</label>
                        <div class="col-md-3">
                            <g:select class="form-control m-b" name="sex" id="sex" from="${['男','女']}" value="${this.contact?.sex}" noSelection="${["": '请选择性别']}"/>
                        </div>

                        <label class="col-md-2 control-label is-required">所占份额</label>
                        <div class="col-md-3 input-group">
                            <g:textField class="form-control" type="text" name="sharePoint" id="sharePoint" value="${this.contact?.sharePoint}"/>
                            <!-- <span class="input-group-addon">%</span> -->
                        </div>
                    </div>
                        
                    <g:textField class="form-control hidden" type="text" name="targetUri" id="targetUri" value="${params.targetUri}"/>
                    <g:textField class="form-control hidden" type="text" name="collateral" id="collateral" value="${this.params?.collateral}"/>

                    <div class="form-group ">
                        <label class="col-md-2 control-label is-required">联系电话</label>
                        <div class="col-md-3">
                            <g:textField class="form-control" type="text" name="cellphone" id="cellphone" value="${this.contact?.cellphone}"/>
                        </div>

                        <label class="col-md-2 control-label is-required">婚姻状态</label>
                        <div class="col-md-3">
                            <g:select class="form-control m-b" name="maritalStatus" id="maritalStatus"
                                      from="${com.cindata.Contact.constrainedProperties.maritalStatus.inList}"
                                      value="${this.contact?.maritalStatus}"
                                      noSelection="${["": '请选择婚姻状态']}"/>
                        </div>
                    </div>

                    <div class="form-group ">
                        <label class="col-md-2 control-label">出身年月日</label>
                        <div class="col-md-3">
                            <g:datePicker class="form-control" name="birthday" value="${new Date()}" precision="day"/>
                        </div>
                        <label class="col-md-2 control-label is-required">学历</label>
                        <div class="col-md-3">
                            <g:select class="form-control" name="degree" id="degree" from="${com.cindata.Contact.constrainedProperties.degree.inList}" value="${params?.priceFluctuationsRatio}" noSelection="${["": '请选择学历']}"/>
                        </div>
                    </div>


                    <div class="form-group ">
                        <label class="col-md-2 control-label is-required">证件类型</label>
                        <div class="col-md-3" >
                            <g:select class="form-control" name="identityType" id="identityType"
                                      optionKey="id" optionValue="name"
                                      from="${com.cindata.dictionary.ContactIdentityType.list()}"
                                      value="${this.contact?.identityType}"
                                      noSelection="${["": '请选择证件类型']}"/>
                        </div>
                        <label class="col-md-2 control-label is-required">证件号</label>
                        <div class="col-md-3">
                            <g:textField class="form-control" type="text" name="idNumber" id="idNumber" value="${this.contact?.idNumber}"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3 col-md-offset-6">
                            <g:submitButton class="btn btn-info" name="create" value="保存"/>
                        </div>
                    </div>
</g:form>
<asset:javascript src="homer/vendor/jquery-validation/jquery.validate.min.js"/>
<g:javascript>
    $(function () {
        $('.datepicker').datepicker({
            language: 'zh-CN',
            format:"yyyy-mm-dd"
        });
        $('.input-group.date').datepicker({ });
        $('.input-daterange').datepicker({ });
        $.validator.addMethod("isMobilOrPhone", function(value,element) {
            var mobile = /^(13|15|18)\d{9}$/;
            var tel =  /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/;
            return this.optional(element) || (tel.test(value) || mobile.test(value));
        }, "请正确填写联系电话");

        $(".createForm").validate({
            ignore: "",
            rules:{
                fullName:{
                    required:true,
                },
                typeId:{
                    required:true,
                },
                sex:{
                    required : true
                },
                sharePoint:{
                    required : true
                },
                cellphone:{
                    required:true,
                    isMobilOrPhone : true
                },
                maritalStatus:{
                    required : true
                },
                degree:{
                    required : true
                },
                identityType:{
                    required : true
                },
                idNumber:{
                    required : true
                },
            },
            messages:{
                fullName:{
                    required:"请输入姓名",
                },
                typeId:{
                    required:"请选择共有人类型",
                },
                sex:{
                    required:"请选择性别"
                },
                sharePoint:{
                    required : "请输入所占份额"
                },
                cellphone:{
                    required:"请输联系电话"
                },
                maritalStatus:{
                    required : "请选择婚姻状态"
                },
                degree:{
                    required : "请选择学历"
                },
                identityType:{
                    required : "请选择证件类型"
                },
                idNumber:{
                    required : "请输入证件号"
                }
            }
        });
    });
</g:javascript>
</body>
</html>
